import axios from 'axios'
import qs from 'qs'

function req(type, url, params, success, fail) {
	axios({
		method: type,
		url:url,
		//url: "/dkcs/apis" + url,
		headers: {},
		params: type == "get" ? qs.stringify(params) : '',
		data: type == "post" ? qs.stringify(params) : '',
	}).then(function(res) {
		if (success) {
			success(res.data);
		} else if (failure) {
			failure(res.data);
		} else {
			console.log('error: ' + JSON.stringify(res.data));
		}
	})
}



export default {
	get: function(url, params, success, fail) {
		return req('get', url, params, success, fail);
	},
	post: function(url, params, success, fail) {
		return req('post', url, params, success, fail);
	}
}
